| 1 |  |  | /* global API */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Nextcloud - passman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright Copyright (c) 2016, Sander Brand ([email protected]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | (function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     'use strict'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @ngdoc function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @name passmanApp.controller:MainCtrl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @description | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * # MainCtrl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Controller of the passmanApp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     angular.module('passmanExtension') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         .controller('SetupCtrl', ['$scope', '$timeout', '$location', '$rootScope', 'StepsService', function ($scope, $timeout, $location, $rootScope, StepsService) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $scope.settings = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 nextcloud_host: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 nextcloud_username: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 nextcloud_password: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 ignoreProtocol: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 ignoreSubdomain: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 ignorePath: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 generatedPasswordLength: 12, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 remember_password: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 remember_vault_password: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 vault_password: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 refreshTime: 60, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 default_vault: {}, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 master_password: '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 disableAutoFill: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 disablePasswordPicker: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 disable_browser_autofill: true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 debug: false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $scope.vaults = []; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             $scope.gogo = function (to) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |                 StepsService.steps().goTo(to); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             }; | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             $scope.check = { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                 server: function (callback) { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                     PAPI.host = $scope.settings.nextcloud_host; | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                     PAPI.username = $scope.settings.nextcloud_username; | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                     PAPI.password = $scope.settings.nextcloud_password; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |                     PAPI.getVaults(function (vaults) { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                         if (vaults.hasOwnProperty('error')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                             var errors = API.i18n.getMessage('invalid_response_from_server', [vaults.result.status, vaults.result.statusText]); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                             $scope.errors.push(errors); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                             callback(false); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                         } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |                         else { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                             $scope.vaults = vaults; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |                             callback(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |                         } | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                         $scope.$apply(); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                     }); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |                 }, | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |                 vault: function (callback) { | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |                     try { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |                         PAPI.decryptString($scope.settings.default_vault.challenge_password, $scope.settings.vault_password); | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |                         callback(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |                     catch (e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |                         $scope.errors.push(API.i18n.getMessage('invalid_vault_password')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                         callback(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 master: function (callback) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                     if ($scope.settings.master_password.trim() !== '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                         callback(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                         $scope.errors.push(API.i18n.getMessage('empty_master_key')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                         callback(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $scope.saving = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $scope.next = function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 $scope.saving = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                 $scope.errors = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 $timeout(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                     var step = StepsService.getCurrent().name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                     var check = $scope.check[step]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                     if (typeof check === "function") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                         check(function (result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                             $scope.saving = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                             if (result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                                 $scope.errors = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                                 $scope.$apply(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                                 StepsService.steps().next(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                             $timeout(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                                 $scope.errors = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                                 $scope.$apply(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                             }, 5000); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                     else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                         $scope.saving = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                         StepsService.steps().next(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 }, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             $scope.finished = function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 var settings = angular.copy($scope.settings); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 var master_password = settings.master_password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                 var master_password_remember = settings.master_password_remember; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 delete settings.master_password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                 delete settings.master_password_remember; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 $scope.saving = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 API.runtime.sendMessage(API.runtime.id, { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                     method: "setMasterPassword", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                     args: {password: master_password, savePassword: master_password_remember} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                     .then(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                         API.runtime.sendMessage(API.runtime.id, { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                             method: "saveSettings", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                             args: settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                         }).then(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                             setTimeout(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                                 window.location = '#!/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                                 $scope.saving = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                             }, 1500); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         }]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | }()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 156 |  |  |  |